package com.anlw.data;


import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;

/*
 * 分页结果类
 */
public class QueryResult<T> {

	private List<T> resultList;// 查询结果
	private long totalResult;// 总记录数

	public List<T> getResultList() {
		return resultList;
	}

	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}

	public long getTotalResult() {
		return totalResult;
	}

	public void setTotalResult(long totalResult) {
		this.totalResult = totalResult;
	}

	
	public String getResult(String em) {
		JSONObject json = new JSONObject();
		try {
			json.put("total", totalResult);
			json.put("rows", resultList);
			String xml = XML.toString(json);
			String jsonstring = json.toString();

			if ("xml".equalsIgnoreCase(em)) {
				return xml;
			} else {
				return jsonstring;
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return null;

	}

}
